import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { EquipmentBaseEntity } from "./equipment-base.entity";

@Entity("character_equipment_inventory")
@ManualTimestamp()
export class CharacterEquipmentInventoryEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId", comment: "角色ID" })
  characterId!: number;

  @Column("int", { name: "equipmentId", comment: "装备ID" })
  equipmentId!: number;

  @Column("int", { default: 1, comment: "装备数量" })
  num!: number;

  @Column("int", {
    default: 1,
    comment: "装备状态：1-正常，0-已使用，-1-已丢弃" })
  status!: number;

  @Column("int", { default: 0, comment: "是否绑定：0-不绑定，1-绑定" })
  isBound!: number;

  @Column("varchar", { length: 100, nullable: true, comment: "装备名称" })
  name!: string;

  @Column("varchar", { length: 100, nullable: true, comment: "装备图片" })
  pic!: string;

  @Column("varchar", { length: 500, nullable: true, comment: "装备描述" })
  description!: string;

  @Column("int", { default: 2, comment: "装备类型：2-装备" })
  itemType!: number;

  @Column("int", { default: 0, comment: "装备稀有度" })
  rarity!: number;

  @Column("int", { default: 1, comment: "装备等级" })
  level!: number;

  @Column("int", { default: 0, comment: "装备负重" })
  weight!: number;

  @Column("varchar", { length: 255, nullable: true, comment: "装备价格" })
  price!: string;

  @Column("text", { nullable: true, comment: "装备介绍" })
  intro!: string;

  // 装备条件字段
  @Column("int", { default: 0, comment: "需要等级" })
  reqLevel!: number;

  @Column("int", { default: 0, comment: "需要力量" })
  reqStrength!: number;

  @Column("int", { default: 0, comment: "需要体质" })
  reqConstitution!: number;

  @Column("int", { default: 0, comment: "需要敏捷" })
  reqAgility!: number;

  @Column("int", { default: 0, comment: "需要智力" })
  reqIntelligence!: number;

  // 装备增益效果字段
  @Column("int", { default: 0, comment: "攻击力加成" })
  bonusAttack!: number;

  @Column("int", { default: 0, comment: "气血加成" })
  bonusHp!: number;

  @Column("int", { default: 0, comment: "精力加成" })
  bonusMp!: number;

  @Column("int", { default: 0, comment: "防御力加成" })
  bonusDefense!: number;

  @Column("varchar", { length: 50, nullable: true, comment: "随机抗性类型" })
  resistanceType!: string;

  @Column("int", { default: 0, comment: "抗性值" })
  resistanceValue!: number;

  @Column("datetime", { comment: "获得时间" })
  obtainedAt!: Date;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", comment: "更新时间", nullable: true })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity)
  @JoinColumn({ name: "equipmentId" })
  character!: CharacterEntity;

  @ManyToOne(() => EquipmentBaseEntity)
  @JoinColumn({ name: "equipmentId" })
  equipmentBase!: EquipmentBaseEntity;
}
